<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <input type="hidden" class="summer-input" id="userId"/>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>设备ID</th>
		        <th>广告文字</th>
		        <th>二维码</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		ADVERT_LIST: basePath + '${common_url}advertList',
		INIT_ADD_ADVERT: basePath + '${common_url}initAddAdvert',
		INIT_EDIT_ADVERT: basePath + '${common_url}initEditAdvert',
		INIT_ADVERT_VIEW: basePath + '${common_url}initViewAdvert',
		DEL_ADVERT: basePath + '${common_url}delAdvert'
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAddAdvert']
		});
        $("#userId").val(${userID});
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAddAdvert"]', function() {
        	var userId = $("#userId").val();
        	window.location.href = CONST_URL.INIT_ADD_ADVERT+"?userId="+userId; 	  	
 		});
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEditAdvert"]', function() {
        	var $this = $(this),
    	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_EDIT_ADVERT+"?id="+id; 	  	
 		});
        
      //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:delAdvert"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL_ADVERT + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
      
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initViewAdvert"]', function() {
        	var $this = $(this),
    	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_ADVERT_VIEW+"?id="+id; 	  	
 		});
    	 
        createTable();
        
    });
    
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"userId": trimSpace($('#userId').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.ADVERT_LIST,
    			param: {
    				"userId": trimSpace($('#userId').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'userId'/* ,
    		    	 render: function (rowData) {
    		    		 return '<a href="javascript:;" data-permit="${name_english}:initAdvertView" class="link">'+ rowData.id +'</a>';
    		    	 } */
    		     },
    		     {
    		    	 field: 'wordAdvert'
    		     },
    		     {
    		    	 field:'qcode'
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 2,    //显示数量
    		    			 permit: ['${name_english}:initEditAdvert','${name_english}:delAdvert'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    	    ]
    	});
    }

   
   
</script>
</body>
</html>